// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel.runtime;

import java.util.List;
import zombie.core.math.PZMath;
import zombie.core.skinnedmodel.ModelManager;
import zombie.core.skinnedmodel.animation.AnimationClip;
import zombie.core.skinnedmodel.animation.Keyframe;
import zombie.scripting.ScriptParser;

public final class CopyFrame implements IRuntimeAnimationCommand {
    protected int m_frame;
    protected int m_FPS = 30;
    protected String m_source;
    protected int m_sourceFrame;
    protected int m_sourceFPS = 30;

    @Override
    public void parse(ScriptParser.Block block) {
        for (ScriptParser.Value value : block.values) {
            String string0 = value.getKey().trim();
            String string1 = value.getValue().trim();
            if ("source".equalsIgnoreCase(string0)) {
                this.m_source = string1;
            } else if ("frame".equalsIgnoreCase(string0)) {
                this.m_frame = PZMath.tryParseInt(string1, 1);
            } else if ("sourceFrame".equalsIgnoreCase(string0)) {
                this.m_sourceFrame = PZMath.tryParseInt(string1, 1);
            }
        }
    }

    @Override
    public void exec(List<Keyframe> keyframes) {
        AnimationClip animationClip = ModelManager.instance.getAnimationClip(this.m_source);

        for (int _int = 0; _int < 60; _int++) {
            Keyframe[] keyframe0 = animationClip.getBoneFramesAt(_int);
            if (keyframe0.length != 0) {
                Keyframe keyframe1 = keyframe0[0];
                Keyframe keyframe2 = new Keyframe();
                keyframe2.Bone = keyframe1.Bone;
                keyframe2.BoneName = keyframe1.BoneName;
                keyframe2.Time = (float)(this.m_frame - 1) / (float)this.m_FPS;
                keyframe2.Position = KeyframeUtil.GetKeyFramePosition(
                    keyframe0, (float)(this.m_sourceFrame - 1) / (float)this.m_sourceFPS, (double)animationClip.Duration
                );
                keyframe2.Rotation = KeyframeUtil.GetKeyFrameRotation(
                    keyframe0, (float)(this.m_sourceFrame - 1) / (float)this.m_sourceFPS, (double)animationClip.Duration
                );
                keyframe2.Scale = keyframe1.Scale;
                keyframes.add(keyframe2);
            }
        }
    }
}
